<?php $this->placeholder('select_fanpages')->captureStart() ?>
<?php $arrPageList    = $this->social->getPageList(); ?>
<?php if( !empty($arrPageList) ):?>
	<div class="sm_select_fanpage forie">
	<form action="post">
	<?php
		$id_page              = Zend_Controller_Front::getInstance()->getRequest()->getParam('id_page',null);
		$arrOptions     = array();
		$arrCommon      = array(
			'module'				=> 'store',
			'controller'			=> 'store',
			'action'                => 'list'
		);
		foreach(array(''=> $this->translate('SELECT_ALL_FANPAGES'))+$arrPageList as $key => $value)
		{
			$arrOptions[$this->url(array_merge($arrCommon,array('id_page' => !empty($key)?$key:null)),null,true)] = $value;
		}
		$element = new Zend_Form_Element_Select('pages',
			array(
				'class'         => 'pages'
			)
		);
		$element->removeDecorator('Label');
		$element->removeDecorator('HtmlTag');
		$element->addMultiOptions($arrOptions);
		$element->setValue($this->url(array_merge($arrCommon,array('id_page' => $id_page)),null,true));
	?>
	<?php echo $element;?>
	<?php if( !empty($id_page) && isset($arrPageList[$id_page]) ):?>
		<span class="greenbutton view">
			<a href="<?php echo $this->social->getFanPageUrl($id_page, $arrPageList[$id_page]);?>" target="_blank"><?php echo $this->translate('GO')?></a>
		</span>
	<?php endif;?>
	</form>
	</div>
	<script type="text/javascript">
	jQuery("document").ready(function($){
		$("#<?php echo $element->getId() ?>").ymSelectPage({
			title	: '<?php echo $this->translate('Confirm this action') ?>',
			template:'<?php echo YouNet_Util::htmlToJs($this->partial('store/ask_install_page.phtml'))?>',
			translate:{
				ADD_FANPAGE_SUCCESSFUL:"<?php echo $this->translate('ADD_FANPAGE_SUCCESSFUL')?>"
			}
		});
	});
	</script>
<?php else:?>
	<div class="sm_select_fanpage">
		<span class="btn_green">
			<a href="#" id="btn_load_list_page">
				<?php echo $this->translate('LOAD_MY_FANPAGES') ?>
			</a>
		</span>
	</div>
	<script type="text/javascript">
	jQuery("document").ready(function($){
		$('#btn_load_list_page').click(function(e){
			e.preventDefault();
			authorizeManagePages('<?php echo $this->socialUrl(array());?>');
		});
	});
	</script>
<?php endif;?>
<?php $this->placeholder('select_fanpages')->captureEnd() ?>